package com.huaixia.cozeapi.response;

/**
 * @author biliyu
 * @date 2024/06/25
 */
public class ResultTemplate {

    /**
     * 成功
     *
     * @return
     */
    public static ApiResponse success() {
        ApiResponse apiResponse = new ApiResponse(null);
        return apiResponse;
    }

    /**
     * 成功
     *
     * @param object
     * @return
     */
    public static ApiResponse success(Object object) {
        ApiResponse apiResponse = new ApiResponse(object);
        return apiResponse;
    }

    /**
     * 失败
     */
    public static ApiResponse error(ResponseCodeInterface response) {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(response.getCode());
        apiResponse.setMsg(response.getMsg());
        return apiResponse;
    }

    /**
     * 失败
     */
    public static ApiResponse error(String msg) {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(ResponseCode.ERROR.getCode());
        apiResponse.setMsg(msg);
        return apiResponse;
    }

    /**
     * 失败时也返回数据
     */
    public static ApiResponse errorData(ResponseCodeInterface response,Object object) {
        ApiResponse apiResponse = new ApiResponse(object);
        apiResponse.setCode(response.getCode());
        apiResponse.setMsg(response.getMsg());
        return apiResponse;
    }

    /**
     * 失败返回code和msg
     */
    public static ApiResponse errorCodeMsg(int code, String msg) {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(code);
        apiResponse.setMsg(msg);
        return apiResponse;
    }

    /**
     * 失败返回code和msg和data
     */
    public static ApiResponse errorCodeMsgData(int code, String msg, Object o) {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(code);
        apiResponse.setMsg(msg);
        apiResponse.setData(o);
        return apiResponse;
    }

    /**
     * 失败时也返回数据
     */
    public static ApiResponse errorAndData(int code, Object object) {
        ApiResponse apiResponse = new ApiResponse(object);
        apiResponse.setCode(code);
        apiResponse.setData(object);
        return apiResponse;
    }

}
